package com.ebeijia.service.user.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ebeijia.common.FileOperation;
import com.ebeijia.mybatis.mapper.CommonUserMapper;
import com.ebeijia.mybatis.mapper.NoticeInfoMapper;
import com.ebeijia.mybatis.pojo.NoticeInfo;
import com.ebeijia.mybatis.pojo.UserInfo;
import com.ebeijia.service.user.NoticeService;
import com.ebeijia.util.DateUtil;
import com.ebeijia.web.ResponseMessage;

@Service("noticeService")
public class NoticeServiceImpl implements NoticeService {

	@Autowired
	private NoticeInfoMapper noticeMapper;

	/***
	 * 查询所有的公告
	 * 
	 * @return
	 */
	public List<NoticeInfo> queryNoticeList(String noticetype) {
		NoticeInfo noticeInfo = new NoticeInfo();
		noticeInfo.setNoticeBusType(noticetype);
		return noticeMapper.queryNoticeList(noticeInfo);
		// return commonMapper.getAllNotice();

	}

	public ResponseMessage queryNoticeInfoById(String id) throws Exception {
		NoticeInfo noticeInfo = noticeMapper.selectByPrimaryKey(id);
		if(noticeInfo==null){
			return ResponseMessage.error("不存在此信息!");
		}
		String noticePath=noticeInfo.getNoticeConPath();
		String  content=FileOperation.readTxtFile(noticePath);
		noticeInfo.setNoticeContent(content);
		noticeInfo.setDeployDate(DateUtil.formatDate(noticeInfo.getNoticeDepDate(), "yyyy-MM-dd"));
		return ResponseMessage.success(noticeInfo);

	}

}
